__author__ = 'YinDu'

from config import *
from flask_restful import Resource
from flask import Flask, request, jsonify
from flask_restful.reqparse import RequestParser

app = Flask(__name__)
app.config.from_object(DevelopConfig)  # 先指定配置类


def request_flask_restful(list_value):
    """
        :param list_value: receive incoming information
        :return: to view
    """
    parser = RequestParser()
    for the_value in list_value:
        parser.add_argument(the_value[0], type=the_value[1], location='json')
    return parser.parse_args()


def err_response(code=None, mage=None, data=None):
    """
    :param code: the error code value
    :param mage: the error message
    :param data: wrong data
    :return: error information
    """
    err_response_data = {'error_on': -1, 'err_remind': 'The system is faulty'}
    if code:
        err_response_data['error_on'] = code
    if mage:
        err_response_data['err_remind'] = mage
    if data:
        err_response_data['data'] = data
    return err_response_data


def normal_response(code=None, mage=None, data=None):
    """
    :param code: the code value
    :param mage: the message
    :param data: the data you want to output
    :return: information
    """
    err_response_data = {'code': 2000, 'mage': ''}
    if code:
        err_response_data['code'] = code
    if mage:
        err_response_data['mage'] = mage
    if data:
        err_response_data['data'] = data
    return err_response_data
